#include <iostream>
using namespace std;

struct TreeNode {
	int val;
	TreeNode *left;
	TreeNode *right;
	TreeNode() : val(0), left(nullptr), right(nullptr) {}
	TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
	TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}
};
class Solution {
private:
	int getHeight(TreeNode* node){
		if(node == nullptr) return 0;
		int leftHeight = getHeight(node->left);
		if(leftHeight == -1){
			return -1;
		}
		int rightHeight = getHeight(node->right);
		if(rightHeight == -1){
			return -1;
		}
		if(abs(leftHeight - rightHeight) > 1){
			return -1;
		}
		return 1 + max(leftHeight,rightHeight);
	}
public:
	bool isBalanced(TreeNode* root) {
		int res = getHeight(root);
		if(res == -1){
			return false;
		}
		return true;
	}
};
int main(){
	return 0;
}
